﻿using System;
using System.Collections.Generic;
using System.EnterpriseServices;
using System.EnterpriseServices.CompensatingResourceManager;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace Reflexive.IO.Transactions
{
    //http://msdn.microsoft.com/en-us/magazine/cc301514.aspx
    //http://msdn.microsoft.com/en-us/library/8xkdw05k(VS.80).aspx
    //http://www.codeproject.com/Articles/1013/Applying-COM-Chapter-Compensating-Resource-Manag
    //http://msdn.microsoft.com/en-us/library/windows/desktop/ms684168(v=vs.85).aspx
    //http://msdn.microsoft.com/en-us/library/windows/desktop/ms687054(v=vs.85).aspx
    //http://stackoverflow.com/questions/2693857/file-system-transactions-using-net-on-winxp


    [Transaction]
    // Create a Worker class.
    [Guid("F91BE825-D9AF-47BF-8E14-BC3931A48CF1")]
    public class CompensatingWorker : ServicedComponent
    {
        public CompensatingWorker():base()
        {
        
        }
        public void CRMMethod(string fileName, bool bCommit)
        {
            // Create clerk object.
            Clerk clerk = new Clerk(typeof(CompensatingResourceManager),
                 "CompensatingResourceManager", CompensatorOptions.AllPhases);
            clerk.WriteLogRecord(fileName);
            clerk.ForceLog();
            if (bCommit)
                ContextUtil.SetComplete();
            else
                ContextUtil.SetAbort();
        }

    }
}
